package edu.uclm.esi.tysw.podtube.persistence;

import java.io.FileInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.sql.CallableStatement;
import java.sql.SQLException;

import edu.uclm.esi.tysw.podtube.domain.Audio;

public class AudioDAO {
	public static void insert(Audio audio) throws SQLException, FileNotFoundException {
		Conexion bd = Broker.get().getBD();
		try {
			//File file = new File(audio.getTempFileName());
			//FileInputStream fi = new FileInputStream(file);
			CallableStatement cs = bd.prepareCall("{call insertarAudio (?, ?, ?, ?, ?, ?, ?, ?)}");
			cs.setString(1, audio.getHash()); 			// pHash
			cs.setBytes(2, audio.getContenido()); 		// pContenido
			cs.setString(3, audio.getTrueFileName()); 	// pFileName
			cs.setInt(4, audio.getUsuario().getId()); 	// pIdUsuario
			cs.setString(5, audio.getPalabraClave1()); 	// pPC1
			cs.setString(6, audio.getPalabraClave2()); 	// pPC2
			cs.setString(7, audio.getPalabraClave3()); 	// pPC3
			cs.registerOutParameter(8, java.sql.Types.VARCHAR);	// pExito
			cs.executeUpdate();
		} finally {
			bd.close();
		}
	}
}
